package com.wbcs.system.tags;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.wbcs.system.assistant.TagAssistant;

public class DataImportTag extends BodyTagSupport
{
    private static final long serialVersionUID=2884967750630773439L;

    private final static Log log=LogFactory.getLog(DataImportTag.class);

    private String ref;

    private String dataimportinitsize;//初始大小，可配置值包括max/normal，分别表示最大化、最小化、正常窗口大小（即上面pagewidth/pageheight配置的大小）
    
    private String popupparams;
    
    public String getRef()
    {
        return ref;
    }

    public void setRef(String ref)
    {
        this.ref=ref;
    }

    public void setDataimportinitsize(String dataimportinitsize)
    {
        this.dataimportinitsize=dataimportinitsize;
    }

    public String getPopupparams()
    {
        return popupparams;
    }

    public void setPopupparams(String popupparams)
    {
        this.popupparams=popupparams;
    }

    @Override
	public int doStartTag() throws JspException
    {
        return EVAL_BODY_BUFFERED;
    }

    @Override
	public int doEndTag() throws JspException
    {
        if(ref==null||ref.trim().equals(""))
        {
            throw new JspException("必须指定<wx:dataimport/>的ref属性");
        }
        BodyContent bc=getBodyContent();
        String label=null;
        if(bc!=null) label=bc.getString();
        JspWriter out=pageContext.getOut();
        try
        {
            out.println(TagAssistant.getInstance().getDataImportDisplayValue(ref,this.popupparams,this.dataimportinitsize,label,
                    (HttpServletRequest)pageContext.getRequest()));
        }catch(IOException e)
        {
            log.error("显示数据导入标签到页面失败",e);
        }
        return EVAL_PAGE;
    }
}
